package com.woniu.p2p.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.p2p.entity.UserScore;
import com.woniu.p2p.service.P2PScoreService;
import com.woniu.p2p.vo.FindMessageVo;
import com.woniu.p2p.vo.ScoreAndUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 86152
 * @create 2020/8/11
 * @since 1.0.0
 */
@RestController
@RequestMapping("/score")
public class P2PScoreController {
    @Autowired
    P2PScoreService p2PScoreService;

    /*查询积分数据*/
    @RequestMapping("/findallscore")
    public PageInfo<UserScore> findallscore(HttpServletRequest request){
        String token = request.getHeader("token");
        int userid = Integer.parseInt(token);
        int start=1;
        int size=4;
        PageInfo<UserScore> userScorePageInfo=p2PScoreService.findallscore(userid,start,size);
        return userScorePageInfo;
    }

    /*通过currentpage获取页面数据*/
    @RequestMapping("/findsinglescorepage")
    public PageInfo<UserScore> findsinglescorepage(@RequestBody FindMessageVo findMessageVo, HttpServletRequest request){
        String token = request.getHeader("token");
        int userid = Integer.parseInt(token);
        Integer start = findMessageVo.getPageNum();
        Integer size = findMessageVo.getPageSize();
        PageInfo<UserScore> userScorePageInfo=p2PScoreService.findallscore(userid,start,size);
        return userScorePageInfo;
    }

    /*查询积分和用户信息*/
    @RequestMapping("/findscorebyid")
    public ScoreAndUserVo findscorebyid(@RequestBody UserScore userScore, HttpServletRequest request){
        String token = request.getHeader("token");
        int userid = Integer.parseInt(token);
        Integer scoreId = userScore.getScoreId();
        ScoreAndUserVo scoreAndUserVo=p2PScoreService.findscoreanduserbyid(userid,scoreId);
        return scoreAndUserVo;
    }
}
